<template>
  <div class="Address">
    <van-nav-bar
      title="设置"
      left-text="返回"
      right-text="更改"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
    <van-address-edit
      :area-list="areaList"
      :address-info="initValue"
      show-postal
      show-delete
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import { Toast } from "vant";
import { postAddress, getdanAdd } from "../services/dress.js";
import area from "../utils/area.js";
export default {
  data() {
    return {
      areaList: area,
      searchResult: [],
      AddressData: [],
      initValue: {},
    };
  },
  created() {
    console.log(this.$route.query.ids);
    getdanAdd(this.$route.query.ids).then((res) => {
      console.log(res);
      this.initValue.name = res.receiver;
      this.initValue.tel = res.mobile;
      this.initValue.isDefault = res.isDefault;
      this.initValue.addressDetail = res.address;
      console.log(this.initValue);
    });
  },
  methods: {
    onClickLeft() {
      Toast("返回");
      this.$router.push({
        name: "AddressList",
      });
    },
    onClickRight() {
      Toast("按钮");
    },
    onSave(v) {
      Toast("save");
      console.log(v);
      // postAddress(v).then((res) => {
      //   console.log(res);
      // });
      //   this.$router.push({
      //     name: "AddressList",
      //   });
    },
    onDelete() {
      Toast("delete");
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [];
      } else {
        this.searchResult = [];
      }
    },
  },
};
</script>

<style>
</style>